package com.cs224u;

import java.util.Collection;
import java.util.Iterator;

public class Util {
  /**
   * Code that simulates join method found in JavaScript. From:
   * http://stackoverflow.com/questions/1515437/java-function-for-arrays-like-phps-join
   * @param s
   * @return
   */
  public static String join(Collection<String> s) {
    String delimiter = " ";
    StringBuffer buffer = new StringBuffer();
    Iterator<String> iter = s.iterator();
    while (iter.hasNext()) {
      buffer.append(iter.next());
      if (iter.hasNext()) {
        buffer.append(delimiter);
      }
    }
    return buffer.toString();
  }
}
